app.controller("teachingscheduleController",function($scope, $http,$routeParams,$filter){
            $scope.id=$routeParams.id;
            console.log($scope.id);
            $scope.teach_5a_hour_surplus=$routeParams.teach_5a_hour_surplus;
            $scope.teach_8a_hour_surplus=$routeParams.teach_8a_hour_surplus;
            $scope.teach_director_hour_surplus=$routeParams.teach_director_hour_surplus;
             $http({
                method: 'POST',
                url: '/OA/classone2one/list',
                data:$.param({pact_id:$scope.id}),
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            }).success(function (response) {
                console.log(response)               //总条数
                $scope.total = response.data.length;
                //反转函数转化abcd转dcba
                $scope.data = response.data;
                //选择显示的条数
                $scope.values = [{"limit":6}];
                //默认显示的条数
                $scope.selectedLimit=$scope.values[0];
                //默认显示当前页数
                $scope.currentPage = 1;
                if($scope.data != null){
                    $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.currentPage-1),$scope.selectedLimit.limit*$scope.currentPage);
                }else{
                    alert($scope.data);
                }
                $scope.page = {
                "limit":$scope.selectedLimit.limit,"pageSize":5,"pageNo":$scope.currentPage,"totalCount":$scope.total};
                // 定义一个空对象 , 用于更新和保存数据时临时存储
                $scope.prod = {};
                $scope.arrs=response.data;
                console.log($scope.arrs)
                //定义一个单机保存按钮时触发的事件,
                 $scope.delete=function ($index) {
                     if ($index>=0) {
                         if(confirm("是否删除"+$scope.datas[$index+(($scope.page.pageNo-1)*$scope.page.limit)].subject_name+"的申请") ){
                             $http({
                                 method:"POST",
                                 url:'/OA/classone2one/delete',
                                 data:$.param({id:$scope.datas[$index+(($scope.page.pageNo-1)*$scope.page.limit)].id}),
                                 headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                             }).success(function (result) {
                                 if(result.ok==true){
                                     setTimeout(function () {
                                         window.location.reload()
                                     },1)
                                 }
                             })
                         }
                     };
                 }
                 $scope.updata=function ($index) {
                    $("#modifylineclass").modal("show");
                     $("#typeteacher").find("option[value="+$scope.arrs[$index].type+"]").prop("selected","selected");
                     $("#subjectupdatateacher").find("option[value="+$scope.arrs[$index].subject_id+"]").prop("selected","selected");
                     // 一对一排课初始化
                         var subject_name_id=$scope.arrs[$index].subject_id;
                         console.log(subject_name_id);
                         $.ajax({
                             type:"POST",
                             url:"/OA/staff/find?role_id=8",
                             data:{subject_id:subject_name_id,is_class:"all"},
                             dataType:"json",
                             success:function (result) {
                                 for (var i = 0; i < result.data.length; i++) {
                                     $("#teacherupdata").append('<option value='+result.data[i].id+'>'+result.data[i].username+'</option>')
                                 };
                             }
                         })

                     $("#teacherupdata").find("option[value="+$scope.arrs[$index].staff_id+"]").prop("selected","selected");
                     $("#endclasstime").val($scope.arrs[$index].class_date);
                     $("#updatahour").val($scope.arrs[$index].hour)
                     $scope.prod.class_time_have=$scope.arrs[$index].class_time_have;
                     $scope.prod.class_time_over=$scope.arrs[$index].class_time_over;
                     $scope.prod.id=$scope.arrs[$index].id;
                     // 修改后保存事件
                     $scope.save=function () {
                         var id=$scope.prod.id;
                         var out_entry=$("#endclasstime").val();
                             date_departure=out_entry.replace(/-/g,'/');
                             date_departure=new Date(date_departure);
                             date_departure=date_departure.getTime();
                         var class_date=$filter("date")(date_departure, "yyyy-MM-dd");
                         var pact_id=$scope.id;
                         var subject_id=$("#subjectupdatateacher").find("option:selected").val();
                         if(subject_id=="0"){
                             alert("请选择所教科目！");
                             return
                         }
                         var subject_name=$("#subjectupdatateacher").find("option:selected").text()
                         var type=$("#typeteacher").find("option:selected").val();
                         if(type=="0"){
                             alert("请选择老师级别!");
                             return
                         }
                         var staff_id=$("#teacherupdata").find("option:selected").val();
                         var staff_name=$("#teacherupdata").find("option:selected").text();
                         var class_time_have=$("#updatahaveclockpicker").val();
                         var class_time_over=$("#updataoverclockpicker").val();
                         class_time_have=class_time_have+":00";
                         class_time_over=class_time_over+":00";
                         var hour= Number($("#updatahour").val());
                         $http({
                             method: 'POST',
                             url: '/OA/classone2one/update',
                             data:$.param({id:id,pact_id:pact_id,class_date:class_date,subject_id:subject_id,subject_name:subject_name,type:type,staff_id:staff_id,staff_name:staff_name,class_time_have:class_time_have,class_time_over:class_time_over,hour:hour}),
                             headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                         }).success(function (response) {
                             if(response.ok==true){
                                 $("#modifylineclass").modal("hide");
                                 setTimeout(function () {
                                     window.location.reload();
                                 },600)
                             }
                         })
                     }
                     
                 }
             })                                              
            $scope.change = function(selectedLimit){
                $scope.page.limit = selectedLimit.limit;
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            }
            $scope.pageChanged = function(){
                $scope.page.limit = $scope.selectedLimit.limit;
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            }
            $scope.setPage = function (go) {
                $scope.length = Math.ceil($scope.total/$scope.selectedLimit.limit);
                console.log($scope.length);
                if(go > $scope.length){
                    $scope.page.pageNo =  $scope.length;
                    console.log($scope.length);
                    
                }else{
                    $scope.page.pageNo=go; 
                }
                $scope.datas = $scope.data.slice($scope.selectedLimit.limit*($scope.page.pageNo-1),$scope.selectedLimit.limit*$scope.page.pageNo);
            };
            $scope.add=function () {
                var out_entry=$("#starttime").val();
                date_departure=out_entry.replace(/-/g,'/');
                date_departure=new Date(date_departure);
                date_departure=date_departure.getTime();
                var class_date=$filter("date")(date_departure, "yyyy-MM-dd");
                var pact_id=$scope.id;
                var subject_id=$("#subjectteacher").find("option:selected").val();
                if(subject_id=="0"){
                    alert("请选择所教科目！");
                    return
                }
                var subject_name=$("#subjectteacher").find("option:selected").text()
                var type=$("#level").find("option:selected").val();
                if(type=="0"){
                    alert("请选择老师级别!");
                    return
                }
                var staff_id=$("#teacher").find("option:selected").val();
                var staff_name=$("#teacher").find("option:selected").text();
                var class_time_have=$("#haveclockpicker").val();
                var class_time_over=$("#overclockpicker").val();
                    class_time_have=class_time_have+":00";
                    class_time_over=class_time_over+":00";
                var hour=Number($("#addhour").val());
                    $scope.json={pact_id:pact_id,class_date:class_date,subject_id:subject_id,subject_name:subject_name,type:type,staff_id:staff_id,staff_name:staff_name,class_time_have:class_time_have,class_time_over:class_time_over,hour:hour};
                    console.log($scope.json);
                    $http({
                        method: 'POST',
                        url: '/OA/classone2one/create',
                        data:$.param($scope.json),
                        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
                    }).success(function (response) {
                        if(response.ok==true){
                            $("#lineclass").modal("hide");
                            setTimeout(function () {
                                window.location.reload();
                            },600)
                        }else if(response.ok==false){
                            alert(response.message)
                        }
                    })
            }
    // 学员信息展示
    $http({
        method:"POST",
        url:"/OA/one2one/query",
        data:$.param({id:$scope.id}),
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
    }).success(function (response){
        console.log(response)
        $scope.findstudent=response.data;
    })

    })

